/*
 * @Author: zhangshu
 * @email: shiliang.zhang@tuya.com
 * @LastEditors: Please set LastEditors
 * @file name: app_key_callback.c
 * @Description:
 * @Copyright: HANGZHOU TUYA INFORMATION TECHNOLOGY CO.,LTD
 * @Company: http://www.tuya.com
 * @Date: 2022-02-08
 * @LastEditTime: 2022-02-08
 */
#include "tal_network_mgr.h"

#include "app_common.h"
#include "app_key.h"
#include "app_led.h"

// key press flag
STATIC BOOL_T key_press_flag = FALSE;

/**
 * @description: net key press process
 * @param[in] time_ms: key press time in ms
 * @return: none
 */
VOID_T net_key_press_callback(UINT32_T time_ms)
{
  if (time_ms == ZIGBEE_RESET_TIME_MS)
  {
    tal_zg_join_start(ZIGBEE_JOIN_TIMEOUT_MS);
    // set_led_blink_event();

    TAL_PR_TRACE("net key long press 5s\r\n");
  }
  if (!key_press_flag)
  {
    key_press_flag = TRUE;
    // device_status.led |= LED_STATUS_PRESS_SLOW;
    // tal_sw_timer_start(etimer_led_blink_event_id, 0, TAL_TIMER_ONCE);
    button_press_on_indicate();
  }
}

/**
 * @description: long press and release time in ms
 * @param[in] time_ms: key press time in ms
 * @return: none
 */
VOID_T net_key_long_press_release_callback(UINT32_T time_ms)
{
  if (key_press_flag)
  {
    key_press_flag = FALSE;
    TAL_PR_TRACE("net key long press release\r\n");
    button_release_off_indicate();
  }
}

/**
 * @description: short press and release time in ms
 * @param[in] count: click times
 * @return: none
 */
VOID_T net_key_short_press_release_callback(UINT8_T count)
{
  if (key_press_flag)
  {
    key_press_flag = FALSE;
    TAL_PR_TRACE("net key short press release\r\n");
    button_release_off_indicate();
  }
}
